package xin.marcher.module.common.enums.lifecycle;

import java.util.HashMap;
import java.util.Map;

/**
 * 商品状态枚举
 */
public enum ProductStatusEnum {

    /**
     * 准备上架
     */
    PRE_ON_MARKET(1, "准备上架"),

    /**
     * 试销上架
     */
    TRY_SALE_ON_MARKET(2, "试销上架"),

    /**
     * 上架
     */
    PUT_ON_THE_MARKET(3, "上架"),

    /**
     * 预下架
     */
    PRE_EXIT_THE_MARKET(4, "预下架"),

    /**
     * 下架
     */
    EXIT_THE_MARKET(5, "下架"),

    /**
     * 停售
     */
    STOP_SALE(6, "停售");
    private Integer code;

    private String value;

    ProductStatusEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static Map<Integer, String> toMap() {
        Map<Integer, String> map = new HashMap<>(16);
        for (ProductStatusEnum element : ProductStatusEnum.values()) {
            map.put(element.getCode(), element.getValue());
        }
        return map;
    }

    public static ProductStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ProductStatusEnum element : ProductStatusEnum.values()) {
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }

}
